export let baseUrl = "http://43.129.77.172:8080" // 测试
let model = ""

// http://https//admin接口：https//admin/admin0988821.xiaosj.cc
export function request(params) {
	let {
		url,
		data,
		method,
	} = params
	const whiteList = ['/notice/getLast', '/user/get', '/remind/get', '/constant/get', '/team/list', '/team/statistics']
	return new Promise((reslove, reject) => {
		const token = uni.getStorageSync('token')
		const tokenHeader = uni.getStorageSync('tokenHead')
		let Authorization = ""
		if (token) {
			Authorization = tokenHeader + token
		}
		uni.request({
			url: baseUrl + url, //仅为示例，并非真实接口地q址。
			data,
			method,

			header: {
				'Authorization': Authorization,
				'Content-Type': 'application/json'
			},
			success: (res) => {

				if (res.data.code === 200) {
					reslove(res.data)
				} else {
					if (res.data.code == 401) {
						// reslove(res.data)
						console.log(url)
						if (whiteList.indexOf(url) != -1) {
							reslove(res.data)
						} else {
							uni.showModal({
								title: "提示",
								content: res.data.message,

								success: (ret) => {
									if (ret.confirm) {
										uni.navigateTo({
											url: "/pages/loginForCode/loginForCode"
										})
									} else {
										uni.navigateBack()
									}
								}
							})
						}

						console.log("提示登录")
					} else if (res.data.code == 408) {
						uni.showModal({
							title: "提示",
							content: "请设置交易密码",
							success: (ret) => {
								if (ret.confirm) {
									uni.navigateTo({
										url: "/pages/setJYPassword/setJYPassword"
									})
								} 
							}
						})
					} else {
						reslove(res.data)
						uni.showModal({
							title: "提示",
							content: res.data.message || "服务错误",
							showCancel: false,

						})
					}

				}

			},
			fail: (ret) => {
				reject(ret)
			},
			complete: function() {
				uni.hideLoading();
			}
		});
	})
}